using System;
using System.Collections.Generic;
namespace AppToolKit.Data.SqlFilter
{
	public class FilterChain
	{
		private List<ISqlFilter> filters_;
		private List<IExpressionFilter> expressiones_;
		private List<IExpressionFilter> Expressiones
		{
			get
			{
				if (this.expressiones_ == null)
				{
					this.expressiones_ = new List<IExpressionFilter>();
				}
				return this.expressiones_;
			}
		}
		private List<ISqlFilter> Filters
		{
			get
			{
				if (this.filters_ == null)
				{
					this.filters_ = new List<ISqlFilter>();
				}
				return this.filters_;
			}
		}
		public string ApplyExpressions()
		{
			string result = string.Empty;
			List<string> list = new List<string>();
			foreach (IExpressionFilter current in this.Expressiones)
			{
				string text = current.Filter(string.Empty);
				if (text != null && text.Trim() != string.Empty)
				{
					list.Add(text);
				}
			}
			if (list.Count > 0)
			{
				result = string.Join(" and ", list.ToArray());
			}
			return result;
		}
		public string ApplyFilters(string sql)
		{
			foreach (ISqlFilter current in this.Filters)
			{
				sql = current.Filter(sql);
			}
			return sql;
		}
		public void AddFilter(ISqlFilter filter)
		{
			this.Filters.Add(filter);
		}
		public void AddExpression(IExpressionFilter expression)
		{
			this.Expressiones.Add(expression);
		}
	}
}
